getLineFaultData();
function getLineFaultData() {
	$.getJSON('/rest/waveData/getBreakerAllActionDatas', function(result) {
		initActList(result);
	});
}
function initActList(data) {
	var ul = $('<ul></ul>');
	ul.appendTo($("#actList .box-body"));
	for ( var i in data) {
		var li = $('<li></li>').appendTo(ul);
		if (i == 0) {
			li.addClass("active");
		}
		var a = $(
				"<a href='javascript:void(0)' onclick=\"getWaveData('"
						+ data[i][1] + "','" + data[i][3] + "','" + data[i][4]
						+ "','" + data[i][0] + data[i][2] + "跳" + data[i][4]
						+ "')\"></a>").html(
				data[i][0] + data[i][2] + "跳" + data[i][4]).css({
			"font-size" : "16px",
			"cursor" : "pointer",
		}).appendTo(li);
	}
}

function getWaveData(fileId, breakerId, phase, name) {
	$("#sel").html(name);
	$.getJSON('/rest/waveData/getBreakerWaveLetData/' + fileId + "/"
			+ breakerId + "/" + phase, function(result) {
		// {"preFault":[[],[]],"postFault":[[],[]]}
		var rtn = initData(result);
//		drawChart("chart0", rtn[0]);
//		drawChart("chart1", rtn[6]);
		for ( var i in rtn) {
			drawChart("chart" + i, rtn[i]);
		}
	});

}
// 将故障前后数据组织在一起
function initData(data) {
	for ( var i in data["preFault"]) {
		for ( var j in data["postFault"][i]) {
			data["preFault"][i].push(data["postFault"][i][j]);
		}
	}
	return data["preFault"];
}
function drawChart(chartId, data) {
	var xdata = [];
	for (var i = -299; i < 1000; i++) {
		xdata.push((i * 0.2).toFixed(2));
	}
	var chart = new CategoryLine(chartId);
	var opt = chart.getOption();
	opt.dataZoom.show = true;
	chart.setxAxis(xdata);
	chart.setyAxis(data);
	var maxPosition = getMax(data);
	chart.setToolbox(false);
	var title = "";
	switch (chartId) {
	case "chart0":
		title = "原始波形";
		break;
	case "chart1":
		title = "1-0";
		break;
	
	case "chart2": title="1-1"; break; case "chart3": title="2-0"; break;
	case "chart4": title="2-1"; break; case "chart5": title="2-2"; break;
	case "chart6": title="21+22"; break; case "chart7": title="2-3"; break;
	case "chart8": title="3-0"; break; case "chart9": title="3-1"; break;
	 case "chart10": title="3-2"; break;
	 case "chart11": title="3-3"; break;
	}
	 
	chart.setTitle(title);
	chart.setSubTitle(maxPosition + " : " + (maxPosition * 0.2).toFixed(2)
			+ "ms");
	opt.title.left = 'center';
	opt.title.subtextStyle.fontSize = 18;
	opt.title.subtextStyle.color = 'black';
	opt.series[0].label.normal.show = false;
	chart.show();
	return chart.getChart();
}

function getMax(data) {
var max = 0;
var maxPosition = 0;
for (var i = 50; i < data.length; i++) {
	if (Math.abs(data[i]) > max) {
		max = Math.abs(data[i]);
		maxPosition = i;
	}
}
return maxPosition;
}